#!/usr/bin/env bash
# 系统优化子菜单

optimize_menu_show() {
  clear
  echo -e "${YELLOW}【系统优化】${RESET}"
  echo -e "  ${GREEN}1.${RESET} 配置时区 (Asia/Shanghai)"
  echo -e "  ${GREEN}2.${RESET} 开启 BBR 加速"
  echo -e "  ${GREEN}3.${RESET} 配置 Swap 交换分区"
  echo -e "  ${GREEN}4.${RESET} 关闭 IPv6 (运行时 + 持久化)"
  echo -e "  ${GREEN}5.${RESET} 修复 GitHub raw 解析失败"
  echo ""
  echo -e "  ${GREEN}0.${RESET} 返回主菜单"
}

optimize_menu_loop() {
  while true; do
    optimize_menu_show
    read -rp "请选择 [0-5]: " a
    case "$a" in
      1) pick "配置时区 Asia/Shanghai";    run_or_stub set_timezone_shanghai ;;
      2) pick "开启 BBR 加速";             run_or_stub enable_bbr ;;
      3) pick "配置 Swap 交换分区";        run_or_stub setup_swap_interactive ;;
      4) pick "关闭 IPv6 (运行时 + 持久化)"; run_or_stub disable_ipv6_persistent ;;
      5) pick "修复 GitHub raw 解析失败";  run_or_stub fix_github_raw_hosts ;;
      0) break ;;
      *) echo -e "${RED}${BOLD}❌ 无效输入，请重试${RESET}" ;;
    esac
    [[ "$a" != 0 ]] && read -rp "按回车键返回上级..."
  done
}
